/*
*  Copyright (C) 2010-2012 VMware, Inc. All rights reserved.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*     http://www.apache.org/licenses/LICENSE-2.0
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
dojo.declare("Login", wm.Page, {
"preferredDevice": "desktop",
start: function() {
if (window["PhoneGap"]) {
this.restorePhonegapCredentials();
} else {
this.usernameInput.setDataValue(dojo.cookie("user") || "");
this.usernameInput.focus();
}
if (this.wmTitle) this.wmTitle.setCaption(app.name || app.declaredClass);
this.loadingDialog.setMargin(parseInt(this.loadingDialog.widgetToCover.margin) + parseInt(this.loadingDialog.widgetToCover.border));
},
loginButtonClick: function(inSender) {
this.loginErrorMsg.setCaption("");
dojo.cookie("user", this.usernameInput.getDataValue(), {
expires: 365
});
},
onLoginSuccess: function() {
if (window["PhoneGap"]) {
this.phonegapCredentialStorage.setData({
name: this.usernameInput.getDataValue(),
dataValue: this.passwordInput.getDataValue()
});
}
},
loginFailed: function(inResponse) {
this.loginErrorMsg.setCaption("Invalid username or password.");
this.usernameInput.focus();
},
restorePhonegapCredentials: function() {
var username = this.phonegapCredentialStorage.getValue("name");
var password = this.phonegapCredentialStorage.getValue("dataValue");
if (username || password) {
this.usernameInput.setDataValue(username);
this.passwordInput.setDataValue(password);
if (username && password) {
this.loginVariable1.update();
}
}
},
svRegistrationSuccess2: function(inSender, inDeprecated) {
},
buttonRegistrationClick: function(inSender) {
var isValid = true;
if (this.textActivationCode.getDataValue() == undefined || this.textActivationCode.getDataValue() == "") {
isValid = false;
}
if (this.emailEditor1.getDataValue() == undefined || this.emailEditor1.getDataValue() == "") {
isValid = false;
}
if (this.passwordEditor1.getDataValue() == undefined || this.passwordEditor1.getDataValue() == "") {
isValid = false;
}
if (this.nameEditor1.getDataValue() == undefined || this.nameEditor1.getDataValue() == "") {
isValid = false;
}
if (this.primaryPhoneEditor1.getDataValue() == undefined || this.primaryPhoneEditor1.getDataValue() == "") {
isValid = false;
}
if (this.luDoor.dataValue == undefined || this.luDoor.dataValue == "") {
isValid = false;
}
if (this.luBlock.dataValue == undefined || this.luBlock.dataValue == "") {
isValid = false;
}
if (isValid) {
this.svRegistration.update();
} else {
this.ncRequiredFields.update();
}
},
svRegistrationError: function(inSender, inError) {
this.notifyRegistrationFail.input.setValue("text", inError);
this.notifyRegistrationFail.update();
},
svRegistrationSuccess: function(inSender, inDeprecated) {
this.usernameInput.setDataValue(this.emailEditor1.getDataValue());
this.formPanel1.clearData();
},
_end: 0
});

Login.widgets = {
phonegapCredentialStorage: ["wm.Variable", {"saveInPhonegap":true,"type":"EntryData"}, {}],
loginVariable1: ["wm.LoginVariable", {}, {"onError":"loginFailed","onResult":"loadingDialog.hide","onSuccess":"onLoginSuccess"}, {
input: ["wm.ServiceInput", {"type":"loginInputs"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":undefined,"source":"usernameInput.dataValue","targetProperty":"username"}, {}],
wire1: ["wm.Wire", {"expression":undefined,"source":"passwordInput.dataValue","targetProperty":"password"}, {}]
}]
}]
}],
notifyRegistration: ["wm.NotificationCall", {"operation":"toast"}, {}, {
input: ["wm.ServiceInput", {"type":"toastInputs"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":"\"Registered Successfully.Please login  using the credentials\"","targetProperty":"text"}, {}],
wire2: ["wm.Wire", {"expression":"\"Success\"","targetProperty":"cssClasses"}, {}],
wire3: ["wm.Wire", {"expression":"\"center center\"","targetProperty":"dialogPosition"}, {}],
wire1: ["wm.Wire", {"expression":"4000","targetProperty":"duration"}, {}]
}]
}]
}],
svRegistration: ["wm.ServiceVariable", {"inFlightBehavior":"executeLast","operation":"register","service":"RegistrationService"}, {"onError":"svRegistrationError","onSuccess":"svRegistrationSuccess","onSuccess1":"notifyRegistration","onSuccess2":"layerLogin"}, {
input: ["wm.ServiceInput", {"type":"registerInputs"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire1: ["wm.Wire", {"expression":undefined,"source":"textActivationCode.dataValue","targetProperty":"activationCode"}, {}],
wire3: ["wm.Wire", {"expression":undefined,"source":"passwordEditor1.dataValue","targetProperty":"customer.password"}, {}],
wire4: ["wm.Wire", {"expression":undefined,"source":"secondaryPhoneEditor1.dataValue","targetProperty":"customer.secondaryPhone"}, {}],
wire5: ["wm.Wire", {"expression":undefined,"source":"primaryPhoneEditor1.dataValue","targetProperty":"customer.primaryPhone"}, {}],
wire6: ["wm.Wire", {"expression":undefined,"source":"nameEditor1.dataValue","targetProperty":"customer.name"}, {}],
wire7: ["wm.Wire", {"expression":undefined,"source":"emailEditor1.dataValue","targetProperty":"customer.email"}, {}],
wire: ["wm.Wire", {"expression":undefined,"source":"luBlock.selectedItem.blockId","targetProperty":"customer.block.blockId"}, {}],
wire2: ["wm.Wire", {"expression":undefined,"source":"luDoor.selectedItem.doorId","targetProperty":"customer.door.doorId"}, {}]
}]
}]
}],
lvBlocks: ["wm.LiveVariable", {"autoUpdate":false,"inFlightBehavior":"executeLast","startUpdate":false,"type":"com.servicelivedb.data.Block"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":undefined,"source":"textActivationCode.dataValue","targetProperty":"filter.project.projectId"}, {}]
}],
liveView: ["wm.LiveView", {"dataType":"com.servicelivedb.data.Block","view":[{"caption":"BlockId","sortable":true,"dataIndex":"blockId","type":"java.lang.Integer","displayType":"Number","required":true,"readonly":true,"includeLists":true,"includeForms":true,"order":0,"subType":null},{"caption":"BlockName","sortable":true,"dataIndex":"blockName","type":"java.lang.String","displayType":"Text","required":false,"readonly":false,"includeLists":true,"includeForms":true,"order":1,"subType":null}]}, {}]
}],
lvDoor: ["wm.LiveVariable", {"autoUpdate":false,"inFlightBehavior":"executeLast","startUpdate":false,"type":"com.servicelivedb.data.Door"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":undefined,"source":"luBlock.selectedItem","targetProperty":"filter.block"}, {}]
}],
liveView: ["wm.LiveView", {"dataType":"com.servicelivedb.data.Door","view":[{"caption":"DoorId","sortable":true,"dataIndex":"doorId","type":"java.lang.Integer","displayType":"Number","required":true,"readonly":true,"includeLists":true,"includeForms":true,"order":0,"subType":null},{"caption":"DoorName","sortable":true,"dataIndex":"doorName","type":"java.lang.String","displayType":"Text","required":false,"readonly":false,"includeLists":true,"includeForms":true,"order":1,"subType":null}]}, {}]
}],
ncRequiredFields: ["wm.NotificationCall", {"operation":"toast"}, {}, {
input: ["wm.ServiceInput", {"type":"toastInputs"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":"\"Please enter all required fields\"","targetProperty":"text"}, {}],
wire1: ["wm.Wire", {"expression":"4000","targetProperty":"duration"}, {}],
wire2: ["wm.Wire", {"expression":"\"Warning\"","targetProperty":"cssClasses"}, {}],
wire3: ["wm.Wire", {"expression":"\"bottom center\"","targetProperty":"dialogPosition"}, {}]
}]
}]
}],
notifyRegistrationFail: ["wm.NotificationCall", {"operation":"toast"}, {}, {
input: ["wm.ServiceInput", {"type":"toastInputs"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire1: ["wm.Wire", {"expression":"4000","targetProperty":"duration"}, {}],
wire: ["wm.Wire", {"expression":"\"Error\"","targetProperty":"cssClasses"}, {}],
wire2: ["wm.Wire", {"expression":"\"bottom center\"","targetProperty":"dialogPosition"}, {}],
wire3: ["wm.Wire", {"expression":undefined,"source":"svRegistration.dataValue","targetProperty":"text"}, {}]
}]
}]
}],
loadingDialog: ["wm.LoadingDialog", {"_classes":{"domNode":["rounded"]},"caption":"Logging in","captionWidth":"100px"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":undefined,"source":"loginInputPanel","targetProperty":"widgetToCover"}, {}]
}]
}],
layoutBox: ["wm.Layout", {"styles":{"backgroundColor":"#c3deeb"}}, {}, {
headerPanel: ["wm.HeaderContentPanel", {"height":"60px","horizontalAlign":"left","layoutKind":"left-to-right","verticalAlign":"top","width":"100%"}, {}, {
TitleBar: ["wm.Panel", {"_classes":{"domNode":["titlebar"]},"border":"0,0,4,0","height":"100%","horizontalAlign":"left","layoutKind":"left-to-right","verticalAlign":"top","width":"100%"}, {}, {
appNameLabel: ["wm.Label", {"_classes":{"domNode":["wm_FontSizePx_24px"]},"align":"center","caption":"Welcome to Service Live","height":"100%","padding":"4","styles":{"color":"","backgroundGradient":"","backgroundColor":"#c3deeb"},"width":"100%"}, {}]
}]
}],
loginMainPanel: ["wm.Panel", {"height":"100%","horizontalAlign":"center","layoutKind":"left-to-right","padding":"10","verticalAlign":"top","width":"100%"}, {}, {
panel4: ["wm.Panel", {"height":"100%","horizontalAlign":"left","margin":"2","padding":"2","verticalAlign":"top","width":"100%"}, {}],
panelCenter: ["wm.Panel", {"height":"450px","horizontalAlign":"left","verticalAlign":"top","width":"500px"}, {}, {
accordionLayers1: ["wm.AccordionLayers", {"border":"2","borderColor":"#888888","captionHeight":"40","defaultLayer":0,"margin":"2","padding":"2"}, {}, {
layerLogin: ["wm.Layer", {"borderColor":"","caption":"                                      Login","horizontalAlign":"center","themeStyleType":"ContentPanel","verticalAlign":"middle"}, {}, {
loginInputPanel: ["wm.HeaderContentPanel", {"_classes":{"domNode":["rounded"]},"desktopHeight":"222px","deviceType":null,"enableTouchHeight":true,"fitToContentHeight":true,"height":"164px","horizontalAlign":"center","margin":"10","mobileHeight":"290px","padding":"10","styles":{"color":""},"verticalAlign":"top","width":"390px"}, {"onEnterKeyPress":"loginButton.click"}, {
panel1: ["wm.Panel", {"fitToContentHeight":true,"height":"72px","horizontalAlign":"left","verticalAlign":"top","width":"100%"}, {}, {
usernameInput: ["wm.Text", {"caption":"Email Id","captionSize":"120px","dataValue":undefined,"desktopHeight":"35px","displayValue":"","height":"35px","mobileHeight":"45px","placeHolder":"Email Id","regExp":"^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$","width":"100%"}, {}],
passwordInput: ["wm.Text", {"caption":"Password","captionSize":"120px","dataValue":undefined,"desktopHeight":"35px","displayValue":"","height":"35px","mobileHeight":"45px","password":true,"placeHolder":"Password","width":"100%"}, {}]
}],
loginButtonPanel: ["wm.Panel", {"height":"50px","horizontalAlign":"right","layoutKind":"left-to-right","padding":"4","width":"100%"}, {}, {
loginErrorMsg: ["wm.Label", {"align":"center","caption":" ","height":"100%","padding":"4","singleLine":false,"width":"100%"}, {}, {
format: ["wm.DataFormatter", {}, {}]
}],
loginButton: ["wm.Button", {"borderColor":"#000000","caption":"Login","height":"100%","margin":"4","width":"90px"}, {"onclick":"loginButtonClick","onclick2":"loadingDialog.show","onclick3":"loginVariable1"}]
}]
}]
}],
layerRegistration: ["wm.Layer", {"borderColor":"","caption":"Registration","horizontalAlign":"left","themeStyleType":"","verticalAlign":"top"}, {}, {
panel2: ["wm.HeaderContentPanel", {"borderColor":"","height":"100%","horizontalAlign":"left","layoutKind":"left-to-right","margin":"2","padding":"2","verticalAlign":"top","width":"100%"}, {}, {
formPanel1: ["wm.FormPanel", {"captionSize":"150px","desktopHeight":"422px","editorHeight":"35px","height":"422px","mobileHeight":"422px","type":"com.servicelivedb.data.Customer"}, {}, {
textActivationCode: ["wm.Text", {"caption":"Activation Code","captionSize":"150px","dataValue":undefined,"desktopHeight":"35px","displayValue":"","height":"35px","placeHolder":"Project Code","required":true,"width":"100%"}, {"onchange":"lvBlocks"}],
emailEditor1: ["wm.Text", {"caption":"Email","captionSize":"150px","changeOnKey":true,"dataValue":"","desktopHeight":"35px","displayValue":"","emptyValue":"emptyString","height":"35px","placeHolder":"Email Id","regExp":"^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$","required":true,"width":"100%"}, {}],
passwordEditor1: ["wm.Text", {"caption":"Password","captionSize":"150px","changeOnKey":true,"dataValue":"","desktopHeight":"35px","displayValue":"","emptyValue":"emptyString","height":"35px","password":true,"placeHolder":"Password","required":true,"width":"100%"}, {}],
nameEditor1: ["wm.Text", {"caption":"Name","captionSize":"150px","changeOnKey":true,"dataValue":"","desktopHeight":"35px","displayValue":"","emptyValue":"emptyString","height":"35px","placeHolder":"First Name Last Name","required":true,"width":"100%"}, {}],
luBlock: ["wm.Lookup", {"caption":"Block","captionSize":"150px","dataType":"com.servicelivedb.data.Block","dataValue":undefined,"desktopHeight":"35px","displayField":"blockName","displayValue":"","height":"35px","placeHolder":"Select a Block","required":true,"width":"100%"}, {"onchange":"lvDoor"}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":undefined,"source":"lvBlocks","targetProperty":"dataSet"}, {}]
}]
}],
luDoor: ["wm.Lookup", {"caption":"Door","captionSize":"150px","dataType":"com.servicelivedb.data.Door","dataValue":undefined,"desktopHeight":"35px","displayField":"doorName","displayValue":"","height":"35px","placeHolder":"Select a Door","required":true,"width":"100%"}, {}, {
binding: ["wm.Binding", {}, {}, {
wire: ["wm.Wire", {"expression":undefined,"source":"lvDoor","targetProperty":"dataSet"}, {}]
}]
}],
primaryPhoneEditor1: ["wm.Text", {"caption":"PrimaryPhone","captionSize":"150px","changeOnKey":true,"dataValue":"","desktopHeight":"35px","displayValue":"","emptyValue":"emptyString","height":"35px","placeHolder":"Enter a valid Phone Number","required":true,"width":"100%"}, {}],
secondaryPhoneEditor1: ["wm.Text", {"caption":"SecondaryPhone","captionSize":"150px","changeOnKey":true,"dataValue":"","desktopHeight":"35px","displayValue":"","emptyValue":"emptyString","height":"35px","placeHolder":"Enter an alternative contact number","width":"100%"}, {}],
panel3: ["wm.Panel", {"desktopHeight":"50px","enableTouchHeight":true,"height":"50px","horizontalAlign":"right","layoutKind":"left-to-right","mobileHeight":"40px","verticalAlign":"top","width":"100%"}, {}, {
label1: ["wm.Label", {"caption":"<span style='color:red'>* </span> Required fields","padding":"4","styles":{"fontWeight":"bold"},"width":"338px"}, {}],
buttonRegistration: ["wm.Button", {"caption":"Register","height":"100%","margin":"4","width":"120px"}, {"onclick":"buttonRegistrationClick"}]
}]
}]
}]
}]
}]
}],
panel5: ["wm.Panel", {"height":"100%","horizontalAlign":"left","verticalAlign":"top","width":"100%"}, {}]
}]
}]
};

Login.prototype._cssText = '.Login .Login-loginErrorMsg {\
font-size: 12px; color: red\
}\
.Login .Login-wmTitle {\
font-size: 20px;\
}\
.wmmobile .Login .wmeditor .wmlabel {\
font-size: 16px;\
}\
.wmmobile .Login .wmeditor input {\
font-size: 20px;\
}\
.Login div .rounded {\
-webkit-border-radius: 8px;\
-moz-border-radius: 8px;\
border-radius: 8px;\
}\
';
Login.prototype._htmlText = '<div id="sample">Sample Markup</div>\
';